unit frameSevkiyat;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, DB, ADODB;

type
  TfrmSevkiyatKod = class(TFrame)
    Label12: TLabel;
    edKod: TEdit;
    Label3: TLabel;
    edACIKLAMA: TEdit;
    adoTemp: TADOQuery;
    adoTemp2: TADOQuery;
  private
    { Private declarations }
  public
    { Public declarations }
    ID, UNITYCODE: integer;
    procedure SevkAc(Sender: TObject; CariKod: integer);
  end;

implementation
uses data, U_SevkiyatHesabiSec, ana1, U_SevkiyatHesListesi;
{$R *.dfm}

{ TfrmSevkiyatKod }

procedure TfrmSevkiyatKod.SevkAc(Sender: TObject; CariKod: integer);
var Strx: string;
begin
  adotemp.close;
  adotemp.SQL.Text := ' select * from tbl_SevkiyatAdres S join cari U on U.UnityCarikod=S.UNCARIID where 1=1 ';

  if TEdit(sender).Tag = 1 then begin
    if edKod.Text <> '' then begin
      adotemp.SQL.add(' and KODU like :KODU  ');
      adotemp.Parameters.ParamByName('KODU').Value := edKod.Text + '%';
      Strx := edKod.Text;
    end;
  end;

  if TEdit(sender).Tag = 2 then begin
    if edACIKLAMA.Text <> '' then begin
      adotemp.SQL.add(' and ACIKLAMA like :ACIKLAMA  ');
      adotemp.Parameters.ParamByName('ACIKLAMA').Value := edACIKLAMA.Text + '%';
      Strx := edACIKLAMA.Text;
    end;
  end;


  if (carikod <> 0) then begin
    adotemp2.Close;
    adotemp2.SQL.Text := 'Select * from Cari C where C.Carikod=:CKOD';
    adotemp2.Parameters.ParamByName('CKOD').Value := carikod;
    adoTemp2.open;

    if adoTemp2.RecordCount > 0 then
    begin
      adotemp.SQL.add(' and  S.UNCARIID = :SS');
      adotemp.Parameters.ParamByName('SS').Value := adotemp2.fieldbyname('unitycarikod').value;
    end;
  end;

  adotemp.Open;

  if adotemp.RecordCount > 0 then begin
    if not assigned(fmSevkiyatHesabiSec) then
      fmSevkiyatHesabiSec := tfmSevkiyatHesabiSec.create(application);
    fmSevkiyatHesabiSec.FormStyle := fsNormal;

    if TEdit(sender).Tag = 2 then
      fmSevkiyatHesabiSec.Aciklama := Strx;

    if TEdit(sender).Tag = 1 then
      fmSevkiyatHesabiSec.Kodu := Strx;

    if (carikod <> 0) then
      fmSevkiyatHesabiSec.CariID := adotemp2.fieldbyname('unitycarikod').value
    else fmSevkiyatHesabiSec.CariID := 0;

    if fmSevkiyatHesabiSec.ShowModal = mrOk then
    begin
      UNITYCODE := anaform.MODALRESULT[6];
      ID := anaform.MODALRESULT[5];
      edKod.Text := anaform.MODALRESULT[1];
      edACIKLAMA.Text := anaform.MODALRESULT[2];
    end;
  end;
end;

end.

